﻿using System.Drawing;
using System.Windows.Forms;

namespace Windows32
{
    public class PointMouseCapturer : MouseCapturer
    {
        int descMoveInt = 0;
        int isVH = 0;
        Point leftPoint = Point.Empty;
        Point rightPoint = Point.Empty;
        public PointMouseCapturer()
        {

        }

        public PointMouseCapturer(Control control)
        {
            base.BindControl = control;
        }

        public Point LeftPoint
        {
            set
            {
                leftPoint = value;
            }
        }

        public Point RightPoint
        {
            set
            {
                rightPoint = value;
            }
        }

        protected override void OnDraw()
        {
            using (ReversibleDrawer drawer = ReversibleDrawer.FromHwnd(this.myBindControl.Handle))
            {
                drawer.PenStyle = PenStyle.PS_DOT;
                drawer.PenColor = Color.Red;
                if (this.isVH == 1)
                {
                    int x = CurrentPosition.X;
                    if (leftPoint != Point.Empty && rightPoint != Point.Empty)
                    {
                        if (CurrentPosition.X < leftPoint.X)
                            x = leftPoint.X;
                        else if (CurrentPosition.X > rightPoint.X)
                            x = rightPoint.X;
                    }
                    drawer.DrawLine(x, 0, x, this.myBindControl.Height);
                }
                else
                {
                    drawer.DrawLine(0, this.CurrentPosition.Y, this.BindControl.Width, this.CurrentPosition.Y);
                }
            }
        }

        public int VHType
        {
            set
            {
                isVH = value;
            }
        }
    }
}
